package com.zhuss.team.processor;

import com.zhuss.bean.bo.team.information.SearchInfoBo;
import com.zhuss.bean.vo.team.information.DetailInfoVo;
import com.zhuss.bean.vo.team.information.ListInfoVo;
import com.zhuss.common.PageVo;
import com.zhuss.exception.WpsException;
import com.zhuss.exception.ExceptionCode;
import com.zhuss.team.db.dao.ext.InformationDao;
import com.zhuss.team.db.entity.Information;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author: zhushanshuo
 * @Date: 2020/3/4 14:42
 */
@Component("informationRead")
public class InformationRead {

    @Autowired
    private InformationDao informationDao;

    /**
     * 用户列表
     * @param bo
     */
    public Object list(SearchInfoBo bo) {
        PageVo<ListInfoVo> result = new PageVo<ListInfoVo>();
        result.setPageNum(bo.getPageNum());
        result.setPageSize(bo.getPageSize());
        result.setItems(informationDao.list(bo));
        result.setTotal(informationDao.countList(bo));
        return result;
    }

    /**
     * 用户详情
     * @param infoId
     * @throws WpsException
     */
    public Object detail(Long infoId) throws WpsException {
        Object result = informationDao.detail(infoId);
        if (result == null) {
            throw new WpsException(ExceptionCode.数据不存在);
        }
        DetailInfoVo vo = (DetailInfoVo)result;
        Information info = new Information();
        info.setInfoId(infoId);
        info.setHeat(vo.getHeat()+1);
        informationDao.updateByPrimaryKeySelective(info);
        return result;
    }
}
